#include <iostream>
#include <vector>
#include <algorithm>

void countSum(std::vector<int> &nums, int totalv, int idx1, int idx2, std::vector<int> &result)
{
    int N = nums.size();
    idx1 = (idx1 + N) % N;
    idx2 = idx2 % N;

    // std::cout << idx1 << " " << idx2 << std::endl;
    if (idx1 == idx2)
    {
        return;
    }
    if (std::abs(idx1 - idx2) == 1 || (idx2 + 1) % N == idx1)
    {
        result.push_back(totalv + std::min(nums[idx1], nums[idx2]));
        return;
    }

    // select idx1
    if (nums[idx1] > nums[idx2])
    {
        countSum(nums, totalv + nums[idx2], idx1 - 1, idx2 + 1, result);
        countSum(nums, totalv + nums[(idx1 - 1 + N) % N], idx1 - 2, idx2, result);
    }
    else
    {
        countSum(nums, totalv + nums[idx1], idx1 - 1, idx2 + 1, result);
        countSum(nums, totalv + nums[(idx2 + 1) % N], idx1, idx2 + 2, result);
    }
}

int main()
{
    int N;
    std::cin >> N;

    std::vector<int> nums;
    for (int i = 0; i < N; i++)
    {
        int m;
        std::cin >> m;
        nums.push_back(m);
    }

    int max_v = -1;

    for (int i = 0; i < nums.size(); i++)
    {
        std::vector<int> result;
        countSum(nums, nums[i], i - 1, i + 1, result);

        int v = *std::max_element(result.begin(), result.end());
        if (v > max_v)
            max_v = v;
    }
    std::cout << max_v << std::endl;
    return 0;
}